<template>
  <div class="wpwork-common-layout">
    <div class="wpwork-common-layout-center">
      <el-row class="wpwork-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item label="关键词">
              <el-input v-model="listQuery.keyword" placeholder="请输入关键词查询" clearable
                @keyup.enter.native="search()" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()">
                {{$t('common.search')}}</el-button>
              <el-button icon="el-icon-refresh-right" @click="reset()">{{$t('common.reset')}}
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="wpwork-common-layout-main wpwork-flex-main">
        <wpwork-table v-loading="listLoading" :data="list" max-height="100%">
          <el-table-column prop="executionDate" label="日期" show-overflow-tooltip width="150"
            :formatter="wpwork.tableDateFormat">

          </el-table-column>
          <el-table-column prop="type" label="名称" show-overflow-tooltip width="150">
            <template slot-scope="scope">
              <div>
                {{JSON.parse(scope.row.jobinfo).name}}
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="notes" label="巡检地址" width="150">
            <template slot-scope="scope">
              {{JSON.parse(scope.row.jobinfo).notes}}
            </template>
          </el-table-column>
          <el-table-column prop="notes" label="巡检坐标" width="150">
            <template slot-scope="scope">
              {{JSON.parse(scope.row.jobinfo).location}}
            </template>
          </el-table-column>
          <el-table-column prop="notes" label="是否拍照" width="100">
            <template slot-scope="scope">
              {{JSON.parse(scope.row.jobinfo).isphoto}}
            </template>
          </el-table-column>
          <el-table-column prop="notes" label="巡检时间范围" width="260">
            <template slot-scope="scope">
              {{JSON.parse(scope.row.jobinfo).start}} - {{JSON.parse(scope.row.jobinfo).end}}
            </template>
          </el-table-column>
          <el-table-column prop="notes" label="巡检项">
            <template slot-scope="scope">
              {{getxjx(scope.row)}}
            </template>
          </el-table-column>
          <el-table-column prop="inspectionTime" label="巡检时间" :formatter="wpwork.tableDateFormat"
            width="140">
            <template slot-scope="scope">
              {{JSON.parse(scope.row.jobinfo).inspectionTime}}
            </template>
          </el-table-column>
          <el-table-column prop="enabledMark" label="状态" width="100" align="center">
            <template slot-scope="scope">
              <el-tag :type="JSON.parse(scope.row.jobinfo).isinspection=='是'?'success':'info'"
                disable-transitions>
                {{ JSON.parse(scope.row.jobinfo).isinspection=="是"?'已完成':'未完成' }}
              </el-tag>
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作" width="150">
            <template slot-scope="scope">
              <tableOpts @edit="addOrUpdateHandle(scope.row.id)" @del="handleDel(scope.row.id)"
                :editDisabled="scope.row.enabledMark != 0">
                <el-dropdown>
                  <el-button type="text" size="mini">
                    {{$t('common.moreBtn')}}<i class="el-icon-arrow-down el-icon--right" />
                  </el-button>
                </el-dropdown>
              </tableOpts>
            </template>
          </el-table-column> -->
        </wpwork-table>
        <pagination :total="total" :page.sync="listQuery.currentPage"
          :limit.sync="listQuery.pageSize" @pagination="initData" />
      </div>
    </div>
  </div>
</template>
<script>
import { getList } from '@/api/xjxt'

export default {
  name: 'kqgl',
  components: {},
  data() {
    return {
      showAll: false,
      list: [],
      total: 0,
      btnLoading: false,
      listLoading: true,
      listQuery: {
        keyword: '',
        currentPage: 1,
        pageSize: 20
      },
      noticeSourceList: [],
      noticeStatusList: [
        { fullName: "存草稿", enCode: '0' },
        { fullName: "已发送", enCode: '1' },
        { fullName: "已过期", enCode: '2' },
      ],
      noticeStatus: [],
      noticeSource: [],
      expirationTime: [],
      releaseTime: [],
      releaseUser: [],
      creatorUser: [],
      creatorTime: [],
      formVisible: false,
      viewVisible: false
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      // 获取公告类型
      this.$store.dispatch('base/getDictionaryData', { sort: 'NoticeType' }).then(res => {
        this.noticeSourceList = res
      })
      this.listLoading = true;
      getList({ id: "349057407209541", type: "巡检" }).then(res => {
        this.list = res.data
        this.total = res.data.length
        this.listLoading = false
        this.btnLoading = false
      }).catch(() => {
        this.listLoading = false
        this.btnLoading = false
      })
    },
    addOrUpdateHandle(id) {
      this.formVisible = true
      this.$nextTick(() => {
        this.$refs.Form.init(id)
      })
    },
    getxjx(row) {
      let xjx = JSON.parse(JSON.parse(row.jobinfo).inspectionFeedback)
      var str = "";
      xjx.forEach(element => {
        str += element.key + '(' + (element.value == "" ? "未检测" : element.value) + ')，'
      });
      return str;
    },
    handleView(id) {
      this.viewVisible = true
      this.$nextTick(() => {
        this.$refs.View.init(id)
      })
    },
    handleDel(id) {
      this.$confirm(this.$t('common.delTip'), this.$t('common.tipTitle'), {
        type: 'warning'
      }).then(() => {
        delNotice(id).then(res => {
          this.$message({
            type: 'success',
            message: res.msg,
            duration: 1500,
            onClose: () => {
              this.initData()
            }
          })
        })
      }).catch(() => { })
    },
    handlePublish(id) {
      this.$confirm('您确定要发布当前公告, 是否继续?', '提示', {
        type: 'warning'
      }).then(() => {
        releaseNotice(id).then(res => {
          this.$message({
            type: 'success',
            message: res.msg,
            duration: 1500,
            onClose: () => {
              this.initData()
            }
          })
        })
      }).catch(() => { })
    },
    search() {
      this.listQuery = {
        ...this.listQuery,
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        enabledMark: this.noticeStatus,
        type: this.noticeSource,
        expirationTime: this.expirationTime,
        releaseTime: this.releaseTime,
        releaseUser: this.releaseUser,
        creatorUser: this.creatorUser,
        creatorTime: this.creatorTime
      }
      this.initData()
    },
    reset() {
      this.noticeSource = [];
      this.noticeStatus = [];
      this.listQuery.keyword = '';
      this.listQuery.enabledMark = [];
      this.listQuery.type = [];
      this.expirationTime = [];
      this.releaseTime = [];
      this.releaseUser = [];
      this.creatorUser = [];
      this.creatorTime = [];
      this.search()
    }
  }
}
</script>